import App from './App'
import messages from './locale/index'

let i18nConfig = {
	locale: uni.getLocale(),
	messages
}
// #ifndef VUE3
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n(i18nConfig)
import './uni.promisify.adaptor'
import uView from "uview-ui";
import utils from './utils/utils'
const daohang = (val) => {
	let text = "https://www.google.com.tw/maps/place/" + val
	location.href = text;
}
const GetDistance = (val) => {
	var radLat1 = val.to_latitude * Math.PI / 180.0;
	var radLat2 = val.go_latitude * Math.PI / 180.0;
	var a = radLat1 - radLat2;
	var b = val.to_longitude * Math.PI / 180.0 - val.go_longitude * Math.PI / 180.0;
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
		Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * 6378.137; // EARTH_RADIUS;
	s = Math.round(s * 10000) / 10000;
	return (Number(s) / 1000).toFixed(2);
}
const returnKmUnit = (m) => {
	var v;
	if (typeof m === 'number' && !isNaN(m)) {
		if (m >= 1000) {
			v = (m / 1000).toFixed(2) + 'km'
		} else {
			v = Number(m).toFixed(2) + 'm'
		}
	} else {
		v = '0m'
	}
	return v;
}
const phone = (p) => { //拨打電話
	console.log("拨打電話");
	uni.makePhoneCall({
		phoneNumber: p.toString()
	}).catch((e) => {
		// console.log(e)  //用catch(e)来捕獲錯误{makePhoneCall:fail cancel}
	})
}
const lbtpriview = (index, arr) => { //预览圖片
	console.log("预览圖片");
	var i = arr; //獲取当前頁面的轮播圖數据
	//uniapp预览轮播圖
	uni.previewImage({
		current: index, //预览圖片的下标
		urls: i //预览圖片的地址，必须要數组形式，如果不是數组形式就转換成數组形式就可以
	})
}

const jumpdetail = (url, val) => {
	uni.navigateTo({
		url: url + val
	})
}
const jumpurl = (url) => {
	uni.navigateTo({
		url: url
	})
}
const zdyclick = (url) => {
	location.href = url
}
const returnxxjsTime = (time1, time2) => {
	// 取得當前時間
	const now = new Date(time1);
	// 加 5 小時
	now.setHours(now.getHours() + Number(time2));
	// 格式化輸出（年月日時分秒）
	const formattedDateTime = now.toLocaleString(); // 簡易格式化
	return formattedDateTime.replace(/\//g, "-").slice(0, -3);
}
const returnzftext = (val) => {
	if (val == 1) return "點數支付"
	if (val == 2) return "多元支付"
	if (val == 3) return "現金支付"
	if (val == 4) return "信用卡"
	if (val == 5) return "linepay線上支付"
	if (val == 6) return "街口線上支付"
	if (val == 7) return "街口線下支付"
	if (val == 8) return "linepay線下支付"
}
const goShopInfo = (id) => {
	uni.navigateTo({
		url: "/pages_index/shopInfo?id=" + id
	})
}
const httpRequest = require("@/common/httpRequest.js")
Vue.prototype.http = httpRequest
Vue.prototype.daohang = daohang
Vue.prototype.lbtpriview = lbtpriview
Vue.prototype.GetDistance = GetDistance
Vue.prototype.phone = phone
Vue.prototype.returnKmUnit = returnKmUnit
Vue.prototype.jumpdetail = jumpdetail
Vue.prototype.jumpurl = jumpurl
Vue.prototype.zdyclick = zdyclick
Vue.prototype.returnxxjsTime = returnxxjsTime
Vue.prototype.returnzftext = returnzftext
Vue.prototype.goShopInfo = goShopInfo


Vue.use(uView);
Vue.use(utils);
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	i18n,
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import {
	createI18n
} from 'vue-i18n'
export function createApp() {
	const app = createSSRApp(App)
	app.use(i18n)
	return {
		app
	}
}
// #endif